

layui.use(['form','layer','jquery'],function() {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
    $ = layui.jquery;
    load_data()
    $("#logout").click(function() {
        $.ajax({
            url: API_BASE_URL + '/admin?method=doLogOut',
            method: "POST",
            success(res) {
                console.log(res.code)
                if (res.code == 200) {
                    localStorage.removeItem("username");
                    layer.msg('您已退出登录');
                    load_data();
                } else {
                    layer.msg('服务器异常，请联系管理员');
                }
            }
        })
        return false;
    })
    $('.search_article').bind('input propertychange', function() {
        //layer.msg($(".search_article").val())
        let title = $(".search_article").val()
        if (title.length!=0 || title!=""){
            $.ajax({
                url: API_BASE_URL + '/article?method=getSearchResult&title='+title ,
                method: "POST",
                success(res) {
                    if (res.code == 200) {
                        if (res.data.length != 0){
                            for (let i = 0;i<res.data.length;i++){
                                let obj = res.data[i]
                                $(".result_container").append("<a href='content.html?id="+ obj.id +  "'><p class='result_item' >" + obj.title+ "</p></a>")
                            }
                        }
                    } else {
                        layer.msg('服务器异常，请联系管理员');
                    }
                }
            })
        }
        $(".result_container").children().filter("a").remove();
        $(".result_container").children().filter("p").remove();
    })


    $('p').on('click', function() {
        layer.msg("click")
    });

})